//
//  NavBarViewController.m
//  NavBar
//
//  Created by Thiago on 23/07/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "NavBarViewController.h"


@implementation NavBarViewController

@synthesize webView, statsVC, actionVC;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/


// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
	
	self.title = [[NSString alloc] initWithString:@"LotGD"];
	webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 60, 320, 400)];
	
	[webView loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://localhost:8888/LoGD/"]]];
	
	// Create a final modal view controller
	
	UIBarButtonItem *statsButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Stats" style:UIBarButtonItemStylePlain
																	 target:self action:@selector(modalViewAction:)];

	UIBarButtonItem *actionButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Action" style:UIBarButtonItemStylePlain
																		  target:self action:@selector(actionPickerViewAction:)];
	
	self.navigationItem.rightBarButtonItem = statsButtonItem;
	self.navigationItem.leftBarButtonItem = actionButtonItem;
	[actionButtonItem release];
	[statsButtonItem release];
	
	self.view = webView;
}


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

#pragma mark -
#pragma mark API

- (IBAction)modalViewAction:(id)sender
{
    if (self.statsVC == nil)
        self.statsVC = [[[ModalViewController alloc] init] autorelease];
	
	[self.navigationController presentModalViewController:self.statsVC animated:YES];
}

-(void)actionPickerViewAction:(id)sender {
  	if (self.actionVC == nil)
        self.actionVC = [[[ActionPickerViewController alloc] init] autorelease];
	
	[self.navigationController presentModalViewController:self.actionVC animated:YES];
}

@end
